package com.funo.logic.controller;

import cn.hutool.json.JSONUtil;
import com.funo.logic.model.CompilationInParameter;
import com.funo.logic.response.HandleResult;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请求入参合集
 * @author cms
 * @since 2024年7月18日09:42:27
 */
@RestController
@RequestMapping("compilationInParameter")
public class CompilationInParameterController extends AbstractController{

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 根据编排id查询配置的入参
     * @param arrangeId 编排服务id
     * @return HandleResult
     * @author cms
     * @since 2024年7月18日09:45:12
     */
    @GetMapping("getByArrangeId")
    public HandleResult getByArrangeId(String arrangeId) {
        String value = stringRedisTemplate.opsForValue().get(getCacheKey(arrangeId));
        if (StringUtils.isBlank(value)) {
            return HandleResult.success();
        }
        return HandleResult.success(JSONUtil.toBean(value, CompilationInParameter.class));
    }

    public String getCachePrefix() {
        return "compilationInParameter:";
    }
}
